package ylsb.support;

import java.util.Calendar;

public class StringHandle {
	  static final String paNon = "^\\d+$";
	  static final String paEmail = "^[a-z A-Z 0-9 _]+@[a-z A-Z 0-9 _]+(\\.[a-z A-Z 0-9 _]+)+(\\,[a-z A-Z 0-9 _]+@[a-z A-Z 0-9 _]+(\\.[a-z A-Z 0-9 _]+)+)*$";
	  static final String paLoginname = "^[a-zA-Z0-9][a-zA-Z0-9_]{1,19}$";
	  static final String paIdcardNo = "^\\d{17}[\\dX]$";
	  static final String paMobilePhone = "^1\\d{10}$";
	  
	  public static String ConvertToShort(String ppSource, int ppLength) { 
		  return ConvertToShort(ppSource, ppLength, true); 
	  }


	  
	  public static int getStringByteLength(String ppStr) { 
		  return (ppStr.getBytes()).length;
	  }


	  
	  public static String ConvertToShort(String ppSource, int ppByteLength, boolean ppShowDot) {
	    String ppTarget = "";
	    int mmCurrentLength = 0;
	    
	    try {
	      for (int i = 0; i < ppSource.length(); i++) {
	        String mmStr = ppSource.substring(i, i + 1);
	        byte[] tempbyte = mmStr.getBytes();
	        
	        if (mmCurrentLength + tempbyte.length <= ppByteLength) {
	          ppTarget = ppTarget + mmStr;
	          mmCurrentLength += tempbyte.length;
	        } else {
	          ppTarget = ppTarget + "...";
	          break;
	        } 
	      } 
	      return ppTarget;
	    } catch (Exception exception) {
	      
	      return ppTarget;
	    } 
	  }




	  
	  public static boolean isNon(String s) { return s.matches("^\\d+$"); }




	  
	  public static boolean isEmail(String s) { return s.matches("^[a-z A-Z 0-9 _]+@[a-z A-Z 0-9 _]+(\\.[a-z A-Z 0-9 _]+)+(\\,[a-z A-Z 0-9 _]+@[a-z A-Z 0-9 _]+(\\.[a-z A-Z 0-9 _]+)+)*$"); }




	  
	  public static boolean isLoginName(String s) { return s.matches("^[a-zA-Z0-9][a-zA-Z0-9_]{1,19}$"); }



	  
	  public static boolean isIdcardNo(String s) { return s.matches("^\\d{17}[\\dX]$"); }



	  
	  public static boolean isMobilePhone(String s) { return s.matches("^1\\d{10}$"); }

	  public static String tiemString(){
		  Calendar Now = Calendar.getInstance();
		  String mmYear = String.valueOf(Now.get(Calendar.YEAR));
		  String mmMonth = String.valueOf(Now.get(Calendar.MONTH) + 1);
		  String mmDay = String.valueOf(Now.get(Calendar.DAY_OF_MONTH));
		  String mmHour = String.valueOf(Now.get(Calendar.HOUR_OF_DAY));
		  String mmMinute = String.valueOf(Now.get(Calendar.MINUTE));
		  String mmSecond = String.valueOf(Now.get(Calendar.SECOND));
		  String mmTiemString = mmYear + "-" + mmMonth + "-" + mmDay + "-" + mmHour + "-" + mmMinute + "-" + mmSecond;
		  return mmTiemString;
	  }

	public static String shorttiemString(){
		Calendar Now = Calendar.getInstance();
		String mmYear = String.valueOf(Now.get(Calendar.YEAR));
		String mmMonth = String.valueOf(Now.get(Calendar.MONTH) + 1);
		String mmDay = String.valueOf(Now.get(Calendar.DAY_OF_MONTH));
		String mmHour = String.valueOf(Now.get(Calendar.HOUR_OF_DAY));
		String mmMinute = String.valueOf(Now.get(Calendar.MINUTE));
		String mmSecond = String.valueOf(Now.get(Calendar.SECOND));
		String mmTiemString = mmYear + "-" + mmMonth + "-" + mmDay;
		return mmTiemString;
	}




}
